/* Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

/*
  <file> common.h </file>
  <brief>
    A common header for implementing ULS.
    This file is part of ULS, Unified Lexical Scheme.
  </brief>
  <author>
    Stanley J. Hong <babel96@gmail.com>, August 2011.
  </author>
*/

#ifndef __ULS_COMMON_H__
#define __ULS_COMMON_H__

#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <time.h>
#include <errno.h>

#ifdef WIN32
#include <windows.h>
#include <io.h>
#include <direct.h>
#define uls_open _open
#define uls_close(fd) do { if ((fd)>=0) _close(fd); fd = -1; } while (0)
#define uls_read(fd,buf,bufsiz) _read(fd,buf,bufsiz)
#define uls_write(fd,buf,bufsiz) _write(fd,buf,bufsiz)
#define uls_getcwd _getcwd
#define uls_chdir _chdir
#define uls_fdopen _fdopen
#define uls_fileno _fileno
#define uls_getcwd _getcwd
#define uls_chdir _chdir
#else
#include <unistd.h>
#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#define uls_open open
#define uls_close(fd) do { if ((fd)>=0) close(fd); fd = -1; } while (0)
#define uls_read(fd,buf,bufsiz) read(fd,buf,bufsiz)
#define uls_write(fd,buf,bufsiz) write(fd,buf,bufsiz)
#define uls_getcwd getcwd
#define uls_chdir chdir
#define uls_fdopen fdopen
#define uls_fileno fileno
#define uls_getcwd  getcwd
#define uls_chdir chdir
#endif

#include "uls_config.h"
#include "uls_const.h"
#include "uls_type.h"
#include "uls_util.h"

#ifndef _O_BINARY
#define _O_BINARY 0
#endif

#define uls_strlen(a)       strlen((const char *) (a))
#define uls_bzero(dstptr,n) memset((char*)(dstptr),0x00,n)
#define uls_strncmp(a,b,n)  strncmp((const char*) (a), (const char*) (b), n)
#define uls_strcpy(a,b)     strcpy((char*) (a), (const char*) (b))

#endif
